package com.bole.controller;


import com.bole.data.Result;
import com.bole.data.ResultEnum;
import com.bole.dto.car.TbCarDto;
import com.bole.dto.car.TbCarInfoDto;
import com.bole.dto.content.DicContentTypeDto;
import com.bole.feign.CarInfoFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("carinfo")
@Api(value = "车辆具体信息管理api")
public class CarInfoController {

    @Autowired
    private CarInfoFeign carInfoFeign;



    @RequestMapping("toCarInfo")
    public String carSeriesList(){
        return "/car/car_info_list";
    }


    @GetMapping("getCarInfoList")
    @ResponseBody
    @ApiOperation(value = "查询车辆信息", notes = "查询车辆信息")
    public Result getCarInfo() {
        List<TbCarInfoDto> carInFoList = carInfoFeign.getCarInFoList();
        return Result.response(ResultEnum.OK).setData(carInFoList);
    }


    @PostMapping("saveCarInfo")
    @ApiOperation(value = "增加广告分类信息",notes = "增加广告分类信息")
    @ApiImplicitParam(name = "tbCarInfoDto",value = "广告分类对象",required = true,dataTypeClass = TbCarInfoDto.class)
    @ResponseBody
    public Result saveCarInfo(@RequestBody TbCarInfoDto tbCarInfoDto){
        carInfoFeign.saveCarInfo(tbCarInfoDto);
        return Result.response(ResultEnum.OK);
    }


    @PostMapping("toUpdate/{id}")
    @ApiOperation(value = "广告信息回显",notes = "没啥好注释的")
    @ApiImplicitParam(name = "id",value = "广告id",required = true,dataTypeClass = Long.class)
    @ResponseBody
    public Result toUpdate(@PathVariable("id")Long id){
        TbCarInfoDto tbCarInfoDto = carInfoFeign.toUpdate(id);
        return Result.response(ResultEnum.OK).setData(tbCarInfoDto);
    }


    @PostMapping("updateCarInfo")
    @ApiOperation(value = "修改车辆信息",notes = "修改车辆信息")
    @ApiImplicitParam(name = "tbCarInfoDto",value = "车辆信息",required = true,dataTypeClass = TbCarInfoDto.class)
    @ResponseBody
    public Result updateCarInfo(@RequestBody TbCarInfoDto tbCarInfoDto){
        carInfoFeign.updateContentCateInfo(tbCarInfoDto);
        return Result.response(ResultEnum.OK);
    }


    @PostMapping("deleteBatch/{ids}")
    @ApiOperation(value = "批量删除信息",notes = "批量删除信息")
    @ApiImplicitParam(name = "ids",value = "广告id集",required = true,paramType = "path",dataTypeClass = Long.class)
    @ResponseBody
    public Result deleteBatch(@PathVariable("ids")Long[] ids){
        List<Long> idss = new ArrayList<>();
        for (Long id : ids) {
            idss.add(id);
        }
        carInfoFeign.deleteBatch(idss);
        return Result.response(ResultEnum.OK);
    }


}
